

define(function(require,exports,module){  
	exports.init = function(){
		loadDataFromServer();
	};
	
});  

function loadDataFromServer(){
	$.get("/myBank10/myPayment/MyPayController/getAllMyPayWithoutRemark",function(result){
		if(result.STATUS=="SUCCESS"){
			var $myPays=result.myPays;
			//周一
			var $totalMoney_monday=0;
			//周二
			var $totalMoney_tuesday=0;
			//三
			var $totalMoney_wednesday=0;
			//四
			var $totalMoney_thursday=0;
			//五
			var $totalMoney_friday=0;
			//六
			var $totalMoney_saturday=0;
			//七
			var $totalMoney_sunday=0;
			
			$.each($myPays,function(i,myPay){
				var $dayOfWeek = new Date(myPay.time.substr(0,10)).getDay();
				var $money=myPay.amountOfMoney;
				
				switch($dayOfWeek){
					case 0:
						$totalMoney_sunday = $totalMoney_sunday+$money;
						break;
					case 1:
						$totalMoney_monday = $totalMoney_monday+$money;
						break;
					case 2:
						$totalMoney_tuesday = $totalMoney_tuesday+$money;
						break;
					case 3:
						$totalMoney_wednesday = $totalMoney_wednesday+$money;
						break;
					case 4:
						$totalMoney_thursday = $totalMoney_thursday+$money;
						break;
					case 5:
						$totalMoney_friday = $totalMoney_friday+$money;
						break;
					case 6:
						$totalMoney_saturday = $totalMoney_saturday+$money;
						break;
					default:
				}
			});
			
			showChart($totalMoney_sunday,$totalMoney_monday, $totalMoney_tuesday,
					$totalMoney_wednesday,$totalMoney_thursday,$totalMoney_friday,$totalMoney_saturday);
		}else{
			alert(result.FAIL_MESSAGE);
		}
	});
}

function showChart(sunday,monday,tuesday,wednesday,thursday,friday,saturday){
	$('#container').highcharts({
        chart: {
            type: 'column'
        },
        credits:{
        	enabled:false
        },
        title: {
            text: '按星期为周期的支出金额柱状图'
        },
        xAxis: {
            categories: ['周日', '周一', '周二','周三','周四','周五','周六']
        },
        tooltip:{
        	pointFormat:'{point.y}￥'
        },
        yAxis: {
            title: {
                text: '支出金额(￥)'
            }
        },
        series: [{
            name: '一周',
            data: [sunday,monday,tuesday,wednesday,thursday,friday,saturday]
        }]
    });
}